
#include <config.h>
#include <video_manager.h>
#include <string.h>
#include <stdio.h>


PT_VideoOpr pt_VideoOpr_all = NULL;

// 注册单个ptVideoOpr到链表中
void RegisterVideoOpr(PT_VideoOpr ptVideoOpr)
{
    ptVideoOpr->ptNext = pt_VideoOpr_all;
    pt_VideoOpr_all = ptVideoOpr;
}

// 注册所有ptVideoOpr
void RegisterAllVideoOpr(void)
{
    RegisterV4l2();
    // RegisterXXXX();
}


void ShowVideoOprList(viod)
{   
    int i = 0;
    PT_VideoOpr p_tmp = pt_VideoOpr_all;
    while(p_tmp)
    {
        printf("%02d %s\n", i++, p_tmp->name);
		p_tmp = p_tmp->ptNext;
    }
}



PT_VideoOpr GetVideoOprByName(char *name)
{
    PT_VideoOpr p_tmp = pt_VideoOpr_all;
    while (p_tmp)
    {
        if (strcmp(p_tmp->name, name) == 0)
        {
            return p_tmp;
        }
        p_tmp = p_tmp->ptNext;
    }
    return NULL;
}

// 对pt_VideoOpr_all链表中的每一项调用InitDevice函数，初始化ptVideoDevice（真正的初始化）
int InitVideoDevice(char *name, PT_VideoDevice ptVideoDevice)
{
    PT_VideoOpr p_tmp = pt_VideoOpr_all;
    int error;
    while (p_tmp)
    {
        error = p_tmp->InitDevice(name, ptVideoDevice);
        if (error == 0)
        {
            printf("Init %s success.\n", p_tmp->name);
            return 0;
        }
        p_tmp = p_tmp->ptNext;
    }
    printf("InitVideoDevice failed.\n");
    return -1;
}